/**
    @file       2007_V4_A.c
    @date       2013-10-4 22:23
    @author     Yura Gorishniy
    @version    1.00

    @par        The program asks for three natural numbers and finds
                the least common multiple of them
**/


#include <stdio.h>
#include <stdlib.h>


//#define DEBUG

#ifdef DEBUG
    #define ASSERT(cond)                                                                   \
    if (!(cond))                                                                           \
    {                                                                                      \
        printf("The state is wrong: %s, file: %s, line: %d\n", #cond, __FILE__, __LINE__); \
        abort();                                                                           \
    }
#else
    #define ASSERT(cond)
#endif //DEBUG


//#define _EJC

#ifdef  _EJC
    #define OUT if (0)
#else
    #define OUT
#endif // _EJC


/**
    GCD - finds the greatest common divisor of two natural numbers

    @param      num_1   the first number
    @param      num_2   the secod number

    @return             the greatest common divisor of num_1 and num_2
**/

long GCD (long num_1, long num_2);


/**
    LCM - finds the least common multiple of two natural numbers

    @param      num_1   the first  number
    @param      num_2   the second number

    @return             the least common multiple of num_1 and num_2
**/

long LCM (long num_1, long num_2);


/**
    main        asks for three natural numbers
                prints the least common multiple of these numbers

    @return     0 if the program finishes successfully
               -1 if input is incorrect
**/

int main ()
{
    long num_1 = 0, num_2 = 0, num_3 = 0;

    OUT printf ("# This program finds the least common multiple of three natural numbers\n"
                "# The developer:   Yura Gorishniy     <strausmg@gmail.com>\n"
                "# Version 1.00\n"
                "# The file: %s\n"
                "# The compilation time: %s, %s\n\n", strrchr (__FILE__, '\\'), __DATE__, __TIME__);

    OUT printf ("\n" "# Enter three natural numbers (type them and press ENTER)\n");

    if (scanf ("%ld %ld %ld", &num_1, &num_2, &num_3) != 3)
        {
            printf ("\n" "# Incorrect input, try again");
            return -1;
        }

    long lcm_result = LCM (LCM (num_1,num_2), num_3);

    OUT printf ("# The least common multiple of numbers %ld, %ld and %ld:\n", num_1, num_2, num_3);

    printf ("%ld", lcm_result);

return 0;
}


long GCD (long num_1, long num_2)
{
    long gcd = 0;

    if (num_1 % num_2 == 0) gcd = num_2;
    else return GCD (num_2, num_1 % num_2);
}


long LCM (long num_1, long num_2)
{
    long lcm = (num_1 * num_2) / GCD (num_1,num_2);

return lcm;
}
